package com.inspur.edp.ai.flow.node;

import com.inspur.edp.ai.flow.engine.FlowContext;
import com.inspur.edp.ai.flow.engine.strategy.DefaultFlowStrategy;
import com.inspur.edp.ai.flow.metadata.AbsNode;
import com.inspur.edp.ai.flow.spi.NodeExecuteResult;
import com.inspur.edp.ai.flow.spi.NodeExecutor;
import com.inspur.edp.common.expr.evaluator.ExpressEvaluator;
import java.util.Map;

/**
 * @author lizhaorui
 * @date 2025/9/16
 * @description
 */

public class BatchAssignValueNodeExecutor implements NodeExecutor {

    @Override
    public String getKind() {
        return BatchAssignValueNode.KIND;
    }

    @Override
    public NodeExecuteResult execute(FlowContext context, AbsNode node, Map<String, Object> args) {
        BatchAssignValueNode batchSetValueNode = (BatchAssignValueNode) node;
        if (batchSetValueNode.getExpressEvaluators() != null) {
            for (ExpressEvaluator evaluator : batchSetValueNode.getExpressEvaluators()) {
                evaluator.evaluate(args);
            }
        }
        NodeExecuteResult nodeExecuteResult = new NodeExecuteResult();
        nodeExecuteResult.setVariablesToAdd(null);
        String outputPort = batchSetValueNode.getOutputPorts().get(0);
        DefaultFlowStrategy strategy = new DefaultFlowStrategy(node.getId(), outputPort);
        nodeExecuteResult.setFlowStrategy(strategy);
        return nodeExecuteResult;
    }
}